package com.yilin.tms.core.entity.gps.baidu;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.yilin.commons.exception.BusinessException;
import com.yilin.tms.core.entity.gps.Coordinate;

import java.io.Serializable;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class BmfLocation implements Serializable {
    private double lat;
    private double lng;
    private String sourceName;
    private String areaName;

    public BmfLocation() {
    }

    public BmfLocation(double lat, double lng) {
        this.lat = lat;
        this.lng = lng;
    }

    public BmfLocation(Coordinate coordinate) {
        this.lat = coordinate.getLatitude();
        this.lng = coordinate.getLongitude();
    }

    public BmfLocation(String lat, String lng) {
        this.lat = Double.parseDouble(lat);
        this.lng = Double.parseDouble(lng);
    }

    public static BmfLocation parse(String coordinate) {
        try {
            String[] split = coordinate.split(",");
            return new BmfLocation(split[1], split[0]);
        }catch (Exception e){
            throw new BusinessException("BmfLocation.parse fail!");
        }
    }

    @Override
    public String toString() {
        return  lng+ "," + lat;
    }

    public String getSourceName() {
        return sourceName;
    }

    public void setSourceName(String sourceName) {
        this.sourceName = sourceName;
    }

    public String getAreaName() {
        return areaName;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLng() {
        return lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }
}
